<template>
  <div>
    <el-form :inline="true" class="demo-form-inline" :model="cForm">
      <el-form-item label="一级分类">
        <el-select
          placeholder="请选择"
          v-model="cForm.classfiy1ID"
          @change="handler1"
          :disabled="show"
        >
          <el-option
            :label="c1.name"
            :value="c1.id"
            v-for="c1 in classfiy1"
            :key="c1.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="二级分类" :model="cForm">
        <el-select
          placeholder="请选择"
          v-model="cForm.classfiy2ID"
          @change="handler2"
          :disabled="show"
        >
          <el-option
            :label="c2.name"
            :value="c2.id"
            v-for="c2 in classfiy2"
            :key="c2.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="三级分类" :model="cForm">
        <el-select
          placeholder="请选择"
          v-model="cForm.classfiy3ID"
          @change="handler3"
          :disabled="show"
        >
          <el-option
            :label="c3.name"
            :value="c3.id"
            v-for="c3 in classfiy3"
            :key="c3.id"
          ></el-option>
        </el-select>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: "MenuSelect",
  props: ["show"],
  data() {
    return {
      classfiy1: [],
      classfiy2: [],
      classfiy3: [],
      cForm: {
        classfiy1ID: "",
        classfiy2ID: "",
        classfiy3ID: "",
      },
    };
  },
  methods: {
    async GetClassfiy1() {
      let result = await this.$API.attr.reqGetClassfiy1();
      if (result.code == 200) {
        this.classfiy1 = result.data;
      }
    },
    async handler1() {
      this.classfiy2 = [];
      this.classfiy3 = [];
      this.cForm.classfiy2ID = "";
      this.cForm.classfiy3ID = "";
      const { classfiy1ID } = this.cForm;
      this.$emit("getClassfiyId", { classfiyId: classfiy1ID, level: 1 });
      let result = await this.$API.attr.reqGetClassfiy2(classfiy1ID);
      if (result.code == 200) {
        this.classfiy2 = result.data;
      }
    },
    async handler2() {
      this.classfiy3 = [];
      this.cForm.classfiy3ID = "";
      const { classfiy2ID } = this.cForm;
      this.$emit("getClassfiyId", { classfiyId: classfiy2ID, level: 2 });
      let result = await this.$API.attr.reqGetClassfiy3(classfiy2ID);
      if (result.code == 200) {
        this.classfiy3 = result.data;
      }
    },
    handler3() {
      const { classfiy3ID } = this.cForm;
      this.$emit("getClassfiyId", { classfiyId: classfiy3ID, level: 3 });
    },
  },
  mounted() {
    this.GetClassfiy1();
  },
};
</script>

<style>
</style>